﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace QLHH
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class DSHangHoaWindow : Window
    {
        public DSHangHoaWindow()
        {
            InitializeComponent();
        }
        private HoaDon hoadon = new HoaDon();
        private HoaDon hd = new HoaDon();

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataTable dt = hoadon.DanhSachHoaDon();
            datagrid.ItemsSource = dt.DefaultView;
            datagrid.SelectedValuePath = "sohd";
        }

        private void btClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btDelete_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Bạn có muốn xóa hóa đơn này không ?", "Thông Báo", MessageBoxButton.YesNo, MessageBoxImage.Warning);
            if (result == MessageBoxResult.Yes)
            {
                string shd = datagrid.SelectedValue.ToString();
                hd.XoaHoaDon(shd);
                DataRowView rowSelect = (DataRowView)datagrid.SelectedItem;
                rowSelect.Delete();
            }
        }

        private void mnNew_Click(object sender, RoutedEventArgs e)
        {
            DataView dv = (DataView)datagrid.ItemsSource;
            DataRowView row = dv.AddNew();
            HoaDonWindow hdw = new HoaDonWindow(row, true);
            hdw.ShowDialog();
            row.EndEdit();
            datagrid.Items.Refresh();
        }

        private void btEdit_Click(object sender, RoutedEventArgs e)
        {
            DataRowView row = (DataRowView)datagrid.SelectedItem;
            HoaDonWindow hdw = new HoaDonWindow(row, false);
            hdw.ShowDialog();
            row.EndEdit();
            datagrid.Items.Refresh();
        }
    }
}
